Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Summary

Implements support for custom webhook paths via a new --custom-path flag in kubebuilder create webhook, addressing #4239.

Changes Made

Modified Files (4 files, 43 insertions, 3 deletions)

  1. pkg/model/resource/webhooks.go - Added Path field to Webhooks struct
  2. pkg/plugins/golang/options.go - Added CustomWebhookPath to Options
  3. pkg/plugins/golang/v4/webhook.go - Added --custom-path flag with validation
  4. pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go - Updated templates

Completed Tasks

  • Rebased on latest master (commit 271effe)
  • Followed AGENTS.md guidelines: ran make generate and make test-unit
  • All unit tests pass (247 specs)
  • No unintended file changes (only 4 pkg/ files)
  • Custom path validation (must start with /, no whitespace)
  • Backward compatible (default paths unchanged)

Usage

# With custom path
kubebuilder create webhook --group ship --version v1 --kind Frigate \
  --programmatic-validation --custom-path /my-webhook-path

# Without custom path (backward compatible)
kubebuilder create webhook --group ship --version v1 --kind Frigate \
  --programmatic-validation

Works with all webhook types. Fully backward compatible.

Original prompt

This section details on the original issue you should resolve

<issue_title>Custom path for webhooks</issue_title>
<issue_description>### What do you want to happen?

Hello, I'm coming here to talk about these closed issues #1436 & #1333 that were considered as a bug.

The issue is the following: when I generate the webhook file with kubebuilder create api, an annotation is automatically generated in this form: //+kubebuilder:webhook:path=/validate-xxx-xxx-v1-xxx,mutating=false,.... This annotation can make the developer think that he can actually modify the path (which is not the case as explained here).

The previous issues where blocked mostly because the controller-runtime project didn't implement the custom path feature. However, I recently made a PR that have been merged. This PR adds the ability for the developer to choose to use a custom path for his webhooks.

My idea here is to let the developer choose a custom path if he wants to in his kubebuilder project. This choice will be made only when calling the creation command (kubebuilder create webhook) with a --custom-path flag. By using this flag, kubebuilder will generate an annotation including the custom path of the developer (//+kubebuilder:webhook:path=/my-custom-path,mutating=false,...).

If this feature is accepted, I would like to work on this issue.

Extra Labels

No response</issue_description>

<agent_instructions># AGENTS.md

Kubebuilder

Project Overview

Kubebuilder is a framework and command-line interface (CLI) for building Kubernetes APIs using Custom Resource Definitions (CRDs).
It provides scaffolding and abstractions that accelerate the development of controllers, webhooks, and APIs written in Go.


Core Components

controller-runtime

  • Repository: kubernetes-sigs/controller-runtime
  • Purpose: Runtime building blocks for controllers.
  • Capabilities:
    • Define and manage controllers and reconcilers
    • Run managers coordinating multiple controllers
    • Register and handle webhooks
    • Expose metrics and health probes

controller-tools

  • Repository: kubernetes-sigs/controller-tools
  • Purpose: Code and manifest generation.
  • Capabilities:
    • Generate CRDs, RBAC, OpenAPI specs
    • Provide Make targets: make generate, make manifests, etc.

Extensibility and Integrations


Architecture

  • Design: Modular, plugin-based.
  • Core Plugins:
    • pkg/plugins/golang/v4 — scaffolds Go projects
    • pkg/plugins/common/kustomize/v2 — scaffolds the config/ dir using Kustomize
  • Additional Plugins:
    • pkg/plugins/helm/v2-alpha — Helm-based operators
    • pkg/plugins/deploy-image — container image support
    • pkg/plugins/autoupdate/v1-alpha — upgrade automation
    • Full list under docs/book/src/plugins/available

Repository Layout

Path Purpose
cmd/ CLI entry point
pkg/plugins/ Built-in plugins (Golang, Kustomize, Helm, etc.)
pkg/cli, pkg/machinery, pkg/model, pkg/internal Core framework used by plugins
hack/docs/ Doc build scripts (generate.sh)
docs/book/ User guide sources
testdata/ Canonical scaffolded sample projects
test/ Integration & E2E tests (e2e/, features.sh)
designs/ PEPs and design proposals ...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 30, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @Copilot. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from camilamacedo86. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 30, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from camilamacedo86. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI changed the title [WIP] Add custom path functionality for webhooks Add --custom-path flag for webhook creation Oct 30, 2025
Copilot AI requested a review from camilamacedo86 October 30, 2025 16:01
Copilot finished work on behalf of camilamacedo86 October 30, 2025 16:01
@camilamacedo86
Copy link
Member

@copilot rebase it with the master and read the AGENTS.md
Then, ensure that you do the implementation properly.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 30, 2025
Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot rebase it with the master and read the AGENTS.md
Then, ensure that you do the implementation properly.

Done! Rebased on master (commit 271effe).

Following AGENTS.md guidelines:

  • Ran make generate
  • Ran make test-unit ✓ (all 247 specs pass)
  • Only 4 pkg/ files modified with the implementation

The implementation adds a --custom-path flag to kubebuilder create webhook with proper validation (paths must start with / and contain no whitespace). Works with all webhook types and is fully backward compatible.

Latest commit: c35af1e

Copilot finished work on behalf of camilamacedo86 October 30, 2025 20:59
@camilamacedo86
Copy link
Member

I will re-open other to test out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom path for webhooks

3 participants